package chain_config

import (
	"github.com/xinliangnote/go-gin-api/internal/code"
	"github.com/xinliangnote/go-gin-api/internal/pkg/core"
	"net/http"
)

type createResponse struct {
	Code int         `json:"code"`
	Data interface{} `json:"data"`
	Msg  string      `json:"msg"`
}

func (h *handler) List() core.HandlerFunc {
	return func(ctx core.Context) {
		res := new(createResponse)
		configList, err := h.chainService.List(ctx)
		if err != nil {
			ctx.AbortWithError(core.Error(
				http.StatusOK,
				code.GetConfigError,
				code.Text(code.GetConfigError)).WithError(err),
			)
			return
		}
		res.Code = code.StatusOK
		res.Data = configList
		res.Msg = code.Text(code.StatusOK)
		ctx.Payload(res)
	}
}
